package cn.stylefeng.guns.modular.manager.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.manager.entity.ArchiveDestructionDetail;
import cn.stylefeng.guns.modular.manager.mapper.ArchiveDestructionDetailMapper;
import cn.stylefeng.guns.modular.manager.model.params.ArchiveDestructionDetailParam;
import cn.stylefeng.guns.modular.manager.model.result.ArchiveDestructionDetailResult;
import cn.stylefeng.guns.modular.manager.service.ArchiveDestructionDetailService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 * 档案销毁信息明细表 服务实现类
 * </p>
 *
 * @author blesslp
 * @since 2019-11-24
 */
@Service
public class ArchiveDestructionDetailServiceImpl extends ServiceImpl<ArchiveDestructionDetailMapper, ArchiveDestructionDetail> implements ArchiveDestructionDetailService {

    @Override
    public void add(ArchiveDestructionDetailParam param) {
        ArchiveDestructionDetail entity = getEntity(param);
        this.save(entity);
    }

    @Override
    @Transactional
    public void delete(ArchiveDestructionDetailParam param) {

        final Serializable id = getKey(param);
        this.removeById(id);
    }

    @Override
    public void update(ArchiveDestructionDetailParam param) {
        ArchiveDestructionDetail oldEntity = getOldEntity(param);
        ArchiveDestructionDetail newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public ArchiveDestructionDetailResult findBySpec(ArchiveDestructionDetailParam param) {
        return null;
    }

    @Override
    public List<ArchiveDestructionDetailResult> findListBySpec(ArchiveDestructionDetailParam param) {
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(ArchiveDestructionDetailParam param) {
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(ArchiveDestructionDetailParam param) {
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private ArchiveDestructionDetail getOldEntity(ArchiveDestructionDetailParam param) {
        return this.getById(getKey(param));
    }

    private ArchiveDestructionDetail getEntity(ArchiveDestructionDetailParam param) {
        ArchiveDestructionDetail entity = new ArchiveDestructionDetail();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

}
